package servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Enumeration;

public class Servlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
/*        String[] hobbies = req.getParameterValues("hobby");
        for (String hobby : hobbies) {

            System.out.println(new String(hobby.getBytes(""), StandardCharsets.UTF_8));
        }
        System.out.println(req.getParameter("username"));
        System.out.println("=================================");*/
/*        System.out.println(req.getContextPath());
        System.out.println(req.getHeader("accept"));
        System.out.println(req.getMethod());
        System.out.println(req.getRemoteHost());
        System.out.println(req.getRequestURI());
        System.out.println(req.getRequestURL());
        String serverName = req.getServerName();
        System.out.println(serverName);
        HttpSession session = req.getSession();
        session.setAttribute("1","one");
        session.setAttribute("2","two");
        System.out.println(session.getAttribute("1"));
        System.out.println(session.getAttribute("2"));
        HttpServletMapping httpServletMapping = req.getHttpServletMapping();
        System.out.println(httpServletMapping);
        System.out.println("===============================");
        req.setCharacterEncoding("UTF-8");
        System.out.println(req.getCharacterEncoding());
        Enumeration<String> parameterNames = req.getParameterNames();*/
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;UTF-8");
        PrintWriter writer = resp.getWriter();
        writer.write("哈哈");


    }
}
